<template>
	<view>
		<view class="load" v-if="load">
		  <u-loading-icon
		    mode="circle"
		    inactive-color="#fff"
		    text="正在加载..."
		    vertical
		  ></u-loading-icon>
		</view>
		<view v-else>
			<view class="listBox" v-if="Array.isArray(list) && list.length > 0">
				<block v-for="item in list" :key="item.ID">
					<!-- 一起挥组件 -->
					<huiCell :item="item" :tabInd="getTitleTab(item.AppointmentType)" :ossWatermark="ossWatermark"></huiCell>
				</block>
			<view class="blank_space_view"></view>
			</view>
			<block v-else>
				<u-empty
					mode="list"
					width="64"
					height="64"
					:icon="ossPath + '/upload/1715243724251737.png'"
					:show="true"
					iconSize="32"
					text="暂无数据"
				></u-empty>
			</block>
		</view>
		
	</view>
</template>

<script>
import huiCell from "@/components/huiCell/huiCell.vue";
	export default {
		components: {
		  huiCell
		},
		data() {
			return {
				ID:'',
				ossPath: "",
				longitude:'',
				latitude:'',
				PageIndex: 1, //页码
				PageSize: 10, //请求条数
				isMore:false,
				load:true,
				list:[],
				ossWatermark:'',
			};
		},
		async onLoad(e) {
			this.ossPath = this.$ossPath;
			this.ID = e.ID
			await this.getCity();
			this.getList()
			this.ossWatermark = this.$ossWatermark
		},
		async onShow() {
			await this.getCity();
		},
		onPullDownRefresh() {
			this.list = []
			this.load = true
			this.PageIndex = 1
			this.getList()
		},
		onReachBottom() {
			if(this.isMore){
				this.PageIndex++
				this.getList()
			}
		},
		methods:{
			getTitleTab(str){
				return str == '一起挥'?0:str=='找私教'?1:2
			},
			async getList(){
				let params = {
					UserID:this.ID,
					longitude:this.longitude,
					latitude:this.latitude,
					PageIndex:this.PageIndex,
					PageSize:this.PageSize
				}
				let res = await this.$api.post('appointment/pagelist',params)
				if(res.code==0){
					if(this.PageIndex==1){
						this.list = res.data;
					}else{
						this.list = this.list.concat(res.data);
					}
					// 添加userIDList
					this.list.forEach((i) => {
					  i.userIDList = i.Item.map((a) => a.UserID);
					  i.PeopleCount = i.Item.filter((v) => v.Status >= 1);
					  i.Remark = this.repdis(i.Remark);
					});
					// console.log(this.list);
					// 是否加载数据
					this.isMore = Array.isArray(res.data) && res.data.length >= this.PageSize;
					// 返回true
					this.load = false;
					uni.stopPullDownRefresh()
				}
			},
			// 获取定位
			getLocationSysc() {
			  let _this = this;
			  return new Promise((resolve, reject) => {
			    uni.getLocation({
			      type: "gcj02",
			      success: function (res) {
			        resolve(res);
			      },
			      fail: function (err) {
			        const defaultLocation = {
			          latitude: 0,
			          longitude: 0,
			        };
			        resolve(defaultLocation);
			      },
			    });
			  });
			},
			// 获取当前地址并解析
			async getCity() {
			  let loc = await this.getLocationSysc();
			
			  let longitude = loc.longitude;
			  this.longitude = loc.longitude;
			  let latitude = loc.latitude;
			  this.latitude = loc.latitude;
			  let o = {
			    longitude,
			    latitude,
			  };
			},
			//过滤标签
			repdis(msg) {
			  var msg = msg.replace(/<\/?[^>]*>/g, ""); //去除HTML Tag
			  msg = msg.replace(/[|]*\n/, ""); //去除行尾空格
			  msg = msg.replace(/&npsp;/gi, ""); //去掉npsp
			  return msg;
			},
		}
	}
</script>

<style lang="scss">
page{
	background-color: #f6f6f6;
}
.listBox {
    padding: 0 24rpx;
		padding-top: 24rpx;
  }
	.blank_space_view {
	  // width: 100rpx;
	  height: 60rpx;
	}
</style>
